package com.hxht.cmp.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hxht.cmp.entity.Screenshot;
import com.hxht.cmp.mapper.ScreenshotMapper;
import com.hxht.cmp.pojo.ScreenshotPojo;
import com.hxht.cmp.pojo.SearchCriteria;
import com.hxht.cmp.service.ImageLoadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * Created by gaozikun on 2017/9/7 0007.
 */
@Service
public class ImageLoadServiceImpl implements ImageLoadService {

    @Autowired
    private ScreenshotMapper screenshotMapper;

    @Override
    public int insert(Screenshot screenshot) {
        return screenshotMapper.insert(screenshot);
    }

    @Override
    public int deleteByPrimaryKey(long id) {
        return screenshotMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Page<ScreenshotPojo> selectImagePage(String start, String end, String type, List<String> userUidList, int page, int pageSize) {
//        Example example = new Example(Screenshot.class);
//        if (!ObjectUtils.isEmpty(userUidList) && userUidList.size() > 0) {
//            example.createCriteria().andIn("creatUserUid", userUidList);
//        }
//        if (!ObjectUtils.isEmpty(type)) {
//            example.createCriteria().andEqualTo("type", type);
//        }
//        if (!ObjectUtils.isEmpty(start)) {
//            example.createCriteria().andCondition("DATE_FORMAT(date_created, '%Y-%m-%d') >=" + start);
//        }
//        if (!ObjectUtils.isEmpty(end)) {
//            example.createCriteria().andCondition("DATE_FORMAT(date_created, '%Y-%m-%d') <=" + end);
//        }
//
//        example.setOrderByClause("date_created desc");
        return PageHelper.startPage(page, pageSize).doSelectPage(() -> screenshotMapper.selectScreenshotBycondition(userUidList, type, start, end));
    }

    @Override
    public Page<ScreenshotPojo> selectJudgeImageByCondition(SearchCriteria searchCriteria) {
        return PageHelper.startPage(searchCriteria.getPage(), searchCriteria.getPageSize()).doSelectPage(() -> screenshotMapper.selectJudgeImageByCondition(searchCriteria));
    }


}
